<?php

namespace app\apiadmin\model\selled_order;

use app\common\utils\Res;
use think\Model;

class SelledOrderModel extends Model
{

    protected $name = "siyu_order_selled";

    protected $pk = "id";

    /**
     * @author: zwx
     * @Description: 分页查询数据列表
     * @param {*} $map  查询条件
     * @param {*} $offset  分页偏移量
     * @param {*} $limit  每页数量
     * @Date: 2024-05-12 14:53:13
     */    
    public static function pageMap($map,$findName, $offset, $limit)
    {
         
        try {
            $data =  self::alias('o')
            ->field($findName)
            ->join('xh_siyu_course c ',' o.courseid = c.id')
            ->join('xh_siyu_order r ',' r.order_num = o.order_num')
            ->join('xh_siyu_user u ',' r.tel = u.phone')
            ->where($map)->limit($offset, $limit)->group('o.id')->order('o.create_time desc')->select();
            return $data;
        } catch (\PDOException $th) {
            Res::error($th->getMessage());
        }
        
    }

    /**
     * @author: zwx
     * @Description: 查询数据总数
     * @param {*} $map 查询条件
     * @Date: 2024-05-12 14:53:43
     */    
    public static function pageMapCount($map)
    {
        try {
            $data =  self::alias('o')
            ->join('xh_siyu_course c ',' o.courseid = c.id')
            ->join('xh_siyu_order r ',' r.order_num = o.order_num')
            ->where($map)->order('o.create_time desc')->count();
            return $data;
        } catch (\PDOException $th) {
            Res::error($th->getMessage());
        }
    }

}